package com.wdh.kjs.activity;

import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wdh.kjs.R;

import java.util.ArrayList;
import java.util.List;

public class UploadProjectInfoOrgActivity extends BaseTopActivity implements View.OnClickListener {

    private Intent intent;
    private LinearLayout upload_file_org_jichuxinxi;
    private LinearLayout upload_file_org_2;
    private LinearLayout upload_file_org_3;
    private LinearLayout upload_file_org_4;
    private LinearLayout upload_file_org_5;
    private LinearLayout upload_file_org_6;
    private LinearLayout upload_file_org_7;
    private Button bt_makesure;
    private TextView tv_org_jichuxinxinumber;
    private TextView tv_org_jingyingqingkuang;
    private TextView tv_org_zhengxinzhengming;
    private TextView tv_org_cailizhengming;
    private TextView tv_org_caiwubaobiao;
    private TextView tv_org_lawprove;
    private TextView tv_org_otherprove;
    private SharedPreferences sharedPreferences;
    /**
     * 基础信息文件个数
     */
    private String jichusize = "0";
    /**
     * 经营情况材料个数
     */
    private String jingyingsize = "0";
    /**
     * 征信证明
     */
    private String zhengxinsize = "0";
    /**
     * 财力产权证明
     */
    private String cailisize = "0";
    /**
     * 财务报表
     */
    private String caiwusize = "0";
    /**
     * 相关法律材料
     */
    private String lawsize = "0";
    /**
     * 其它补充材料个数
     */
    private String othersize = "0";

    private List<String> idList = new ArrayList<>();
    private List<String> cailiList = new ArrayList<>();
    private List<String> law = new ArrayList<>();
    private List<String> other = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_upload_project_info_org);
        initTopBar("上传资料");
        initview();
        initwidge();

    }

    private void initwidge() {
        sharedPreferences = getSharedPreferences("orgzhaopian", MODE_PRIVATE);

        jichusize = sharedPreferences.getString("jichusize", "0");
        jingyingsize = sharedPreferences.getString("jingyingsize", "0");
        othersize = sharedPreferences.getString("othersize", "0");
        lawsize = sharedPreferences.getString("lawsize", "0");
        zhengxinsize = sharedPreferences.getString("zhengxinsize", "0");
        cailisize = sharedPreferences.getString("cailisize", "0");
        caiwusize = sharedPreferences.getString("caiwusize", "0");

        tv_org_jichuxinxinumber.setText("已有" + jichusize + "个文件");
        tv_org_otherprove.setText("已有" + othersize + "个文件");
        tv_org_lawprove.setText("已有" + lawsize + "个文件");
        tv_org_cailizhengming.setText("已有" + cailisize + "个文件");
        tv_org_zhengxinzhengming.setText("已有" + zhengxinsize + "个文件");
        tv_org_jingyingqingkuang.setText("已有" + jingyingsize + "个文件");
        tv_org_caiwubaobiao.setText("已有" + caiwusize + "个文件");
    }

    @Override
    protected void onResume() {
        super.onResume();
        initwidge();
    }

    private void initview() {
        tv_org_zhengxinzhengming = (TextView) findViewById(R.id.tv_org_zhengxinzhengming);
        tv_org_otherprove = (TextView) findViewById(R.id.tv_org_otherprove);
        tv_org_lawprove = (TextView) findViewById(R.id.tv_org_lawprove);
        tv_org_cailizhengming = (TextView) findViewById(R.id.tv_org_cailizhengming);
        tv_org_jichuxinxinumber = (TextView) findViewById(R.id.tv_org_jichuxinxi);
        tv_org_jingyingqingkuang = (TextView) findViewById(R.id.tv_org_jingyingqingkuang);
        tv_org_caiwubaobiao = (TextView) findViewById(R.id.tv_org_caiwubaobiao);

        bt_makesure = (Button) findViewById(R.id.bt_makesure);
        bt_makesure.setOnClickListener(this);

        upload_file_org_jichuxinxi = (LinearLayout) findViewById(R.id.upload_file_org_jichuxinxi);
        upload_file_org_jichuxinxi.setOnClickListener(this);
        upload_file_org_2 = (LinearLayout) findViewById(R.id.upload_file_org_2);
        upload_file_org_2.setOnClickListener(this);
        upload_file_org_3 = (LinearLayout) findViewById(R.id.upload_file_org_3);
        upload_file_org_3.setOnClickListener(this);
        upload_file_org_4 = (LinearLayout) findViewById(R.id.upload_file_org_4);
        upload_file_org_4.setOnClickListener(this);
        upload_file_org_5 = (LinearLayout) findViewById(R.id.upload_file_org_5);
        upload_file_org_5.setOnClickListener(this);
        upload_file_org_6 = (LinearLayout) findViewById(R.id.upload_file_org_6);
        upload_file_org_6.setOnClickListener(this);
        upload_file_org_7 = (LinearLayout) findViewById(R.id.upload_file_org_7);
        upload_file_org_7.setOnClickListener(this);
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_makesure:
                if (jichusize.equals("0")) {
                    falseDialogShow("请上传基础信息");
                } else if (jingyingsize.equals("0")) {
                    falseDialogShow("请上传经营情况材料");
                } else if (zhengxinsize.equals("0")) {
                    falseDialogShow("请上传征信证明");
                } else if (cailisize.equals("0")) {
                    falseDialogShow("请上传财力产权证明");
                } else if (caiwusize.equals("0")) {
                    falseDialogShow("请上传财务报表材料");
                } else if (lawsize.equals("0")) {
                    falseDialogShow("请上传相关法律材料");
                } else {
                 /*   for (int i = 0; i < cailiList.size(); i++) {
                        idList.add(cailiList.get(i));
                    }
                    for (int i = 0; i < law.size(); i++) {
                        idList.add(law.get(i));
                    }
                    for (int i = 0; i < other.size(); i++) {
                        idList.add(other.get(i));
                    }*/
                    intent = new Intent();
                    intent.setClass(UploadProjectInfoOrgActivity.this, RongziActivity.class);
                    intent.putStringArrayListExtra("jiben", (ArrayList<String>) idList);
                    setResult(1, intent);
                    finish();
                }
                break;
            case R.id.upload_file_org_jichuxinxi: {
                intent = new Intent(this, BaseOrgMessagePushActivity.class);
                startActivityForResult(intent, 1);
                break;
            }
            case R.id.upload_file_org_2: {
                intent = new Intent(this, JingyingcailiaoOrgActivity.class);
                startActivityForResult(intent, 5);
                break;
            }
            case R.id.upload_file_org_3: {
                intent = new Intent(this, ZhengxinZMOrgActivity.class);
                startActivityForResult(intent, 3);
                break;
            }
            case R.id.upload_file_org_4: {//财力产权证明
                intent = new Intent(this, CailiOrgActivity.class);
                startActivityForResult(intent, 4);
                break;
            }
            case R.id.upload_file_org_5: {
                intent = new Intent(this, CaiwubaobiaoActivity.class);
                startActivityForResult(intent, 2);
                break;
            }
            case R.id.upload_file_org_6: {
                intent = new Intent(this, LawProveOrgActivity.class);
                startActivityForResult(intent, 7);
                break;
            }
            case R.id.upload_file_org_7: {
                intent = new Intent(this, OtherProveOrgActivity.class);
                startActivityForResult(intent, 8);
                break;
            }
            default: {
                break;
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        if (resultCode == 1) {
            idList = data.getStringArrayListExtra("jiben");
        }
        if (resultCode == 4) {
            cailiList = data.getStringArrayListExtra("caili");
//            tv_cailizhengming.setText("已有"+cailiList.size()+"个文件");
        }
        if (resultCode == 7) {
            law = data.getStringArrayListExtra("law");
//            tv_lawprove.setText("已有"+law.size()+"个文件");
        }
        if (resultCode == 8) {
            other = data.getStringArrayListExtra("other");
//            tv_otherprove.setText("已有" + other.size()+"个文件");
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    private void falseDialogShow(String hint) {
        View dialog = getLayoutInflater().inflate(R.layout.touzixinxi, null);
//        Button bt_dialog_false_negative = (Button) dialog.findViewById(R.id.bt_dialog_false_negative);
//        Button bt_dialog_false_positive = (Button) dialog.findViewById(R.id.bt_dialog_false_positive);
        TextView tv_dialog_false_hint = (TextView) dialog.findViewById(R.id.touzixinxi);
        tv_dialog_false_hint.setText(hint);
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setView(dialog);
        builder.create();
        final AlertDialog dialogShow = builder.show();
        tv_dialog_false_hint.setOnClickListener(new android.view.View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dialogShow.dismiss();
            }
        });
//        bt_dialog_false_positive.setOnClickListener(new android.view.View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                dialogShow.dismiss();
//            }
//        });
    }
}
